package com.xueqiu.movieplaymanagersystem.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xueqiu.movieplaymanagersystem.entity.Archives;
import com.xueqiu.movieplaymanagersystem.mapper.BlogMapper;
import com.xueqiu.movieplaymanagersystem.service.ArchivesService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author xueqiu
 */
@Service
public class ArchivesServiceImpl implements ArchivesService {
    @Autowired
    private BlogMapper blogMapper;

    /**
     * 查询；新闻档案，并按照年份进行分组，因为分组所以用map形式存储
     * @return 按年份分组的新闻档案
     */
    @Override
    @Transactional(readOnly = true)
    public Map<String, List<Archives>> findArchives() {
        List<Archives> archives = blogMapper.selectArchives();
        return archives.parallelStream().collect(Collectors.groupingBy(Archives::getYear));
    }
}
